/** @jsxImportSource @emotion/react */
import * as React from "react";
import {OriginalViewProps,} from "../../common/base";
import {
    config观测1, config观测2, config观测3, config设备概况, EntranceSetup, Projects记录,
} from "./orcBase";
import {createItem,} from "../../common/eHelper";
import {useRecordList} from "../../hook/useRecordList";
import {setupItemAreaRoute} from "./orcIspConfig";
import {EditStorageContext} from "../../StorageContext";
import {useTheme} from "customize-easy-ui-component";
import {InstrumentReisp, ItemInstrumentTable} from "../../common/Instrument";
import {FrontCover} from "../../mobilecr/editorIN";
import {ActionMapItem} from "../../common/ActionMapItem";
import {DeviceSurveyD} from "../../crane/editor";
import {ProjectR} from "../../gas/utilityNj/ProjectR";
import {DesignParameter} from "./DesignParameter";
import {MainParts} from "./MainParts";
import {PretestCheck} from "./PretestCheck";
import {Documentation} from "./Documentation";
import {StructuralType} from "./StructuralType";
import {PrototypeInsp} from "./PrototypeInsp";
import {Testings} from "./Testings";
import {UnitnameModify} from "./UnitnameModify";
import {ItemConclusion, Measure2Stability, Measure3Insulation, MeasureCritMemDyn} from "./editor";
import {MaxLiftSpeed} from "./MaxLiftSpeed";
import {PortalTilt} from "./TiltSpeed";
import {TurningRadius} from "./Turning";
import {MaxSpeed} from "./Speed";
import {Climbability, ElectricTract, HookTraction, TractionForce} from "./Climbability";
import {RodTensileForce, StopDistance} from "./StopDistance";
import {FaultRecord, Reliability, TestbedShift} from "./TestbedShift";
import {PerforRetest} from "./PerforRetest";
import {ExplosionProof, Resistance} from "./ExplosionProof";
import {PrototypeImg} from "./PrototypeImg";
import {SelfWeight} from "./SelfWeight";


const recordPrintList =[
    createItem('Entrance', <EntranceSetup/>),
    createItem('FrontCover', <FrontCover/>),
    createItem('ProjectList', <ProjectR nrec config={Projects记录} label={'目录页'}/>),
    createItem('Instrument', <ItemInstrumentTable label={'1、主要测量设备性能检查，首次检验'} />),
    createItem('InstrumentReisp', <InstrumentReisp label={'1、主要测量设备性能检查，复检'} />),
    createItem('Survey', <DeviceSurveyD config={config设备概况} label={'2、受检样机概况'}/>),
    createItem('Item', null),
    createItem('DesignParameter', <DesignParameter label={'3、样机主要参数'}/>),
    createItem('MainParts', <MainParts label={'4、主要零部件、安全保护和防护装置'}/>),
    createItem('PretestCheck', <PretestCheck label={'6、试验前检查记录表'}/>),
    createItem('Documentation', <Documentation label={'7、样机技术资料审查'}/>),
    createItem('StructuralType', <StructuralType label={'8、样机检查2.1结构型式检-2.2主要参数'}/>),
    createItem('PrototypeInsp', <PrototypeInsp part={1} label={'8、样机检查2.3整车外观检查-2.8动力系统检查'}/>),
    createItem('PrototypeInsp_16', <PrototypeInsp part={2} label={'8、样机检查2.9传动系统检查-2.13制动系统检查'}/>),
    createItem('PrototypeInsp_33', <PrototypeInsp part={3} label={'8、样机检2.14电气和控制系统-2.14电气和控制系统'}/>),
    createItem('PrototypeInsp_42', <PrototypeInsp part={4} label={'8、样机检2.16安全保护与防护装置-2.17防爆性能'}/>),
    createItem('Testings', <Testings part={1} label={'9、样机试验3.1装卸性能-3.2转向性能试验'}/>),
    createItem('Testings_11', <Testings part={2} label={'9、样机3.3运行性能3.4动力性能3.5制动性能试验'}/>),
    createItem('Testings_19', <Testings part={3} label={'9、样机3.6稳定性3.7电气安全3.8安全保护防护装置'}/>),
    createItem('Testings_34', <Testings part={4} label={'9、样机3.9主要受力结构件强度3.10强化试验3.11防爆性能'}/>),

    createItem('Conclusion', <ItemConclusion label={'10 结论(下结论)11主要结构型式12备注'}/>),
    createItem('Measure', <MeasureCritMemDyn config={config观测1}  label={'13、附表：附表1 测量结果记录(上)'}/>),
    createItem('Measure2', <Measure2Stability config={config观测2} iAname={['倾斜度要']} label={'附表1 测量结果记录(中)'}/>),
    createItem('Measure3', <Measure3Insulation config={config观测3} iAname={['蓄额压50','蓄额压1k']}  label={'附表1 测量结果记录(下)'}/>),
    createItem('SelfWeight', <SelfWeight label={'附表2 车辆自重测定记录表(C2.7)'}/>),
    createItem('MaxLiftSpeed', <MaxLiftSpeed label={'附表3 最大起升速度、下降速度测量'}/>),
    createItem('PortalTilt', <PortalTilt label={'附表4 门架（或货叉架）倾斜速度试验'}/>),
    createItem('TurningRadius', <TurningRadius label={'附表5 最小转弯半径测量'}/>),
    createItem('MaxSpeed', <MaxSpeed label={'附表6 最大行驶速试验'}/>),
    createItem('Climbability', <Climbability label={'附表7-1 满载最大爬坡度'}/>),
    createItem('TractionForce', <TractionForce label={'附表7-2 最大牵引力试验(内燃）'}/>),
    createItem('HookTraction', <HookTraction label={'附表8 最大挂钩牵引力试验(内燃）'}/>),
    createItem('ElectricTract', <ElectricTract label={'附表9 最大牵引力最大挂钩牵引力试验(电动)'}/>),
    createItem('RodTensileForce', <RodTensileForce label={'附表10 牵引杆拉力测定'}/>),
    createItem('StopDistance', <StopDistance label={'附表11 制动距离试验'}/>),
    createItem('TestbedShift', <TestbedShift label={'附表12-1 叉车可靠性强化试验台班记录表'}/>),
    createItem('FaultRecord', <FaultRecord label={'附表12-2 可靠性强化试验故障记录'}/>),
    createItem('Reliability', <Reliability label={'附表12-3 可靠性强化试验记录表3.10.1'}/>),
    createItem('PerforRetest', <PerforRetest label={'附表12-4 强化试验后性能复测'}/>),
    createItem('ExplosionProof', <ExplosionProof label={'附表13 防爆功能叉车温度试验'}/>),
    createItem('Resistance', <Resistance label={'附表14 防爆功能叉车接地电阻'}/>),
    createItem('PrototypeImg', <PrototypeImg label={'14 样机图片'}/>),
    createItem('UnitnameModify', <UnitnameModify label={'15、型式试验报告变更情况'}/>),
];


export const OriginalView=
  React.forwardRef((
    { action,  verId, repId='', rep,}
    :OriginalViewProps, ref
  ) => {
    const context =React.useContext(EditStorageContext);
    if(context == null)    throw new Error("EditStorageContext没有提供");
    const {storage, } =context;
    const theme = useTheme();
    const witnessNos =React.useMemo(() => {
      return storage.见证表?.map((a:any, i:number) => a && a.no);
    }, [storage.见证表]);
    const recordPrintListNow =React.useMemo(() => {
      // config记录[2].l=witnessNos;     //动态的 工作见证 列表注入：
      let routeAreas=[] as any[];
      const impressionismAs =setupItemAreaRoute({rep, orc:storage, theme});
      let extendTags =Reflect.ownKeys(impressionismAs) as string[];
      const oldItCount=recordPrintList.length;
      let prevpos=0;
      for(let p=0; p<oldItCount; p++){
        if(extendTags.indexOf(recordPrintList[p].itemArea)>=0){     //需要展开 扩充的标签
            routeAreas=routeAreas.concat(recordPrintList.slice(prevpos,p));
            const itemConfigs= impressionismAs?.[recordPrintList[p].itemArea];
            let seq = 0;
            let moreItems = [] as any;
            itemConfigs.forEach((area, x) => {
              seq += 1;
              const rowHead =<ActionMapItem key={seq} alone={false} editAreasConf={itemConfigs}
                                                    index={x} sureD editIts={ [] } />;
              moreItems.push(createItem(area.tag, rowHead));
            });
            routeAreas=routeAreas.concat(moreItems);
            prevpos=p+1;
        }
      }
      routeAreas=routeAreas.concat(recordPrintList.slice(prevpos));
      return routeAreas;
    }, [witnessNos, verId, repId,rep, storage?._Oitems, theme]);

    const {list}=useRecordList(ref,rep,recordPrintListNow,action,verId);
    return <React.Fragment>
      {list}
        {/*      <Button  intent="primary"
                   onPress={(e) => { handleSubmit!();
                   }}
          >送打印转换器
          </Button>*/}
    </React.Fragment>;
  } );
